﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace ZPPProj01Logika
{
    public class Baza
    {

        NorthwindEntities baza = new NorthwindEntities();

        public List<Employees> PobierListePracownikow()
        {
            return baza.Employees.ToList();

        }

        public List<Territories> MiastaPracownika(int ID)
        {
            return baza.Employees.Where(e => e.EmployeeID == ID).First().Territories.ToList();
        }

        public string Sprzedaz(int ID)
        {
            decimal sum = 0;
            var zapytanie =
                from orders in
                    (from orderdetails in baza.Order_Details
                     where
                       orderdetails.Orders.Employees.EmployeeID == ID
                     select new
                     {
                         orderdetails.UnitPrice,
                         cosik = "x"
                     })
                group orders by new { orders.cosik } into g
                select new
                {
                    srednia = (System.Decimal)g.Sum(p => p.UnitPrice)
                };
            foreach (var y in zapytanie)
            {
                sum = sum + y.srednia;
            }
            return ((int)sum).ToString();

        }

    }
}
